home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / tee9201.zip / TEE1.ASM < prev    next >
Assembly Source File  |  1992-01-11  |  2KB  |  80 lines

  1. Comment ~
  2.   From: Tom  Barrett
  3.     To: Jim Hill                Date: 08 Jan 92  20:15:00
  4.   Subj: redirecting output
  5.   Conf: `Dr. Debug Conference'
  6. *******************************************************************************
  7.  > I'm wondering if there's any way I can have both "writes"
  8.  > occur.
  9.  
  10. Yessir... just try and locate a tiny little program probably called "tee.com"
  11. and insert it within a piped output like "DIR | tee >save.txt" ... our you can
  12. write a quick one using DEBUG:
  13. [see TEE.MSG for DEBUG script]
  14.  
  15. v1.1  Toad Hall Tweak
  16.  - Rewrote to "standard" TASM/MASM assembly language format.
  17.  - Tweaked to use all available memory (well, this segment anyway),
  18.    other minor tightenings for minimum size, maximum performance.
  19.  
  20. David Kirschbaum
  21. Toad Hall
  22. kirsch@usasoc.soc.mil
  23.  
  24. ~
  25. CSEG    SEGMENT PUBLIC PARA 'CODE'
  26.     ASSUME    CS:CSEG,DS:CSEG,ES:CSEG
  27. CodeStart    equ    $
  28.  
  29.     ORG    100H
  30.  
  31. Tee    PROC    NEAR
  32. ;Free space should be 0FFFFH - our program code,
  33. ;plus leave a little for the stack.
  34.  
  35.     mov    si,offset CodeStart - offset buff- 80H    ;free space    v1.1
  36.     mov    di,offset buff    ;handy constant (buffer offset)        v1.1
  37.  
  38. Tee_Lup:
  39.     xor    bx,bx        ;STDIN
  40.     mov    cx,si        ;amount to read                v1.1
  41.     mov    dx,di        ;buffer starts beyond program code    v1.1
  42.     MOV    AH,3FH        ;Read from file/device
  43.     INT    21H
  44.     jc    Exit        ;read failed, error in AL
  45.     mov    cx,ax        ;bytes read into CX            v1.1
  46.     jcxz    Exit        ;0, we're done (AL=ERRORLEVEL=0)    v1.1
  47.  
  48.     push    cx        ;save for second write later        v1.1
  49.     inc    bx    ;1    ;STDOUT                    v1.1
  50.     mov    dx,di        ;read buffer                v1.1
  51.     MOV    AH,40H        ;write to file/device
  52.     INT    21H
  53. ;Let's put in a little error trapping here
  54. ;in case the STDOUT write device has a problem.
  55.  
  56.     jc    Exit        ;Write error:  die (error in AL)    v1.1
  57.  
  58. ;A "short read" (less than what we requested) is quite all right.
  59. ;Our next loop will return 0 bytes read, and we'll exit then.
  60.  
  61.     inc    bx    ;2    ;STDERR (console)            v1.1
  62.     POP    CX        ;# bytes to write (what we read)
  63.     mov    dx,di        ;read buffer                v1.1
  64.     MOV    AH,40H        ;write to file/device
  65.     INT    21H
  66. ;Assuming write as ok for now (console writes usually are :-)
  67.  
  68.     JMP    Tee_Lup        ;and loop until done
  69.  
  70. Exit:
  71.     mov    ax,4CH        ;terminate, errorlevel in AL
  72.     int    21H
  73.  
  74. Tee    ENDP
  75.  
  76. buff    equ    $
  77.  
  78. CSEG    ENDS
  79.     END    Tee
  80.